package bank_access;

import mware_lib.Config;
import mware_lib.NameServiceMessage;
import mware_lib.Stub;

public class ManagerStub extends ManagerImplBase {
    private NameServiceMessage msg;
    private String splitString = Config.splitString;

    public ManagerStub(NameServiceMessage msg) {
        this.msg = msg;
    }

    @Override
    public String createAccount(String owner, String branch) {
        if(Config.DEBUGGER) System.out.println("createAccount mit Owner: " + owner + ", Branch: " + branch + " und MSG :" + msg.toString());
        Stub stub = new Stub();
        stub.setReference(msg);
        stub.setMethod("createAccount");
        stub.addParameter(String.class, owner);
        stub.addParameter(String.class, branch);

        String receive = stub.send();
        String[] splits = receive.split(splitString);
        if (splits[0].equals("ERROR")) {
            if(Config.DEBUGGER) System.out.println("createAccount ERROR");
            if(Config.DEBUGGER) System.out.println("Manager RuntimeException : " + splits[2] );
            throw new RuntimeException(splits[2]);
        }

        return receive;
    }
}
